/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nach0x.theTVDBrenamer;

import java.io.File;

/**
 *
 * @author nacho
 */
public final class EpisodeAtrb {
    private File file;
    private String extension;
    private String seriesName;
    private String seasonNbr;
    private String episodeNbr;
    private String episodeName;
    private String fileNameRegex;
    public final String DEFAULT_FILENAME_REGEX = "%seriesName%.S%seasonNbr%E%episodeNbr%.%episodeName%.%extension%";

    public EpisodeAtrb() {
        this.fileNameRegex = this.DEFAULT_FILENAME_REGEX;
    }
    
    public EpisodeAtrb(File file) {
        this();
        this.setFile(file);
    }
    
    public String getFormatFileName() {
        String formatFileName = fileNameRegex;
        
        formatFileName = formatFileName.replaceAll("%seriesName%", seriesName);
        formatFileName = formatFileName.replaceAll("%seasonNbr%", seasonNbr);
        formatFileName = formatFileName.replaceAll("%episodeNbr%", episodeNbr);
        formatFileName = formatFileName.replaceAll("%episodeName%", episodeName);
        formatFileName = formatFileName.replaceAll("%extension%", extension);
        
        return formatFileName;
    }

    public String getFileNameRegex() {
        return fileNameRegex;
    }

    public void setFileNameRegex(String fileNameRegex) {
        this.fileNameRegex = fileNameRegex;
    }

    public String getSeasonNbr() {
        return seasonNbr;
    }

    public void setSeasonNbr(String seasonNbr) {
        this.seasonNbr = seasonNbr;
    }

    public String getSeriesName() {
        return seriesName;
    }

    public void setSeriesName(String seriesName) {
        this.seriesName = seriesName;
    }

    public String getEpisodeName() {
        return episodeName;
    }

    public void setEpisodeName(String episodeName) {
        this.episodeName = episodeName;
    }

    public String getEpisodeNbr() {
        return episodeNbr;
    }

    public void setEpisodeNbr(String episodeNbr) {
        this.episodeNbr = episodeNbr;
    }

    public File getFile() {
        return file;
    }

    @SuppressWarnings("empty-statement")
    public void setFile(File file) {
        this.file = file;
        
        int i = file.getName().length() - 1;
        
        for(; i >= 0 && file.getName().charAt(i) != '.'; i--);
        
        this.extension = file.getName().substring(i + 1);
    }

    
}
